
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.path_finder &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.path_finder</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.path_finder</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module finds diffusion paths through a structure based on a given</span>
<span class="sd">potential field.</span>

<span class="sd">If you use PathFinder algorithm for your research, please consider citing the</span>
<span class="sd">following work::</span>

<span class="sd">    Ziqin Rong, Daniil Kitchaev, Pieremanuele Canepa, Wenxuan Huang, Gerbrand</span>
<span class="sd">    Ceder, The Journal of Chemical Physics 145 (7), 074112</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABCMeta</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">interp1d</span>
<span class="kn">import</span> <span class="nn">scipy.signal</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">numpy.linalg</span> <span class="k">as</span> <span class="nn">la</span>


<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.sites</span> <span class="kn">import</span> <span class="n">PeriodicSite</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.vasp.inputs</span> <span class="kn">import</span> <span class="n">Poscar</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Daniil Kitchaev&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Daniil Kitchaev, Ziqin Rong&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;dkitch@mit.edu, rongzq08@mit.edu&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Development&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;March 17, 2015&quot;</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="NEBPathfinder"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.NEBPathfinder">[docs]</a><span class="k">class</span> <span class="nc">NEBPathfinder</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    General pathfinder for interpolating between two structures, where the</span>
<span class="sd">    interpolating path is calculated with the elastic band method with</span>
<span class="sd">    respect to the given static potential for sites whose indices are given</span>
<span class="sd">    in relax_sites, and is linear otherwise.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">start_struct</span><span class="p">,</span>
                 <span class="n">end_struct</span><span class="p">,</span>
                 <span class="n">relax_sites</span><span class="p">,</span>
                 <span class="n">v</span><span class="p">,</span>
                 <span class="n">n_images</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span>
                 <span class="n">mid_struct</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            start_struct, end_struct: Endpoint structures to interpolate</span>
<span class="sd">            relax_sites: List of site indices whose interpolation paths should</span>
<span class="sd">                be relaxed</span>
<span class="sd">            v: Static potential field to use for the elastic band relaxation</span>
<span class="sd">            n_images: Number of interpolation images to generate</span>
<span class="sd">            mid_struct: (optional) additional structure between the start and end structures to help</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span> <span class="o">=</span> <span class="n">start_struct</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__s2</span> <span class="o">=</span> <span class="n">end_struct</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__mid</span> <span class="o">=</span> <span class="n">mid_struct</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__relax_sites</span> <span class="o">=</span> <span class="n">relax_sites</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="n">v</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__n_images</span> <span class="o">=</span> <span class="n">n_images</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__images</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">interpolate</span><span class="p">()</span>

<div class="viewcode-block" id="NEBPathfinder.interpolate"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.NEBPathfinder.interpolate">[docs]</a>    <span class="k">def</span> <span class="nf">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Finds a set of n_images from self.s1 to self.s2, where all sites except</span>
<span class="sd">        for the ones given in relax_sites, the interpolation is linear (as in</span>
<span class="sd">        pymatgen.core.structure.interpolate), and for the site indices given</span>
<span class="sd">        in relax_sites, the path is relaxed by the elastic band method within</span>
<span class="sd">        the static potential V.</span>

<span class="sd">        If a mid point is defined we will interpolate from s1--&gt; mid --&gt;s2</span>
<span class="sd">        The final number of images will still be n_images.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__mid</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># to make arithmatic easier we will do the interpolation in two parts with n images each</span>
            <span class="c1"># then just take every other image at the end, this results in exactly n images</span>
            <span class="n">images_0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span><span class="o">.</span><span class="n">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__mid</span><span class="p">,</span>
                                             <span class="n">nimages</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_images</span><span class="p">,</span>
                                             <span class="n">interpolate_lattices</span><span class="o">=</span><span class="kc">False</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">images_1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__mid</span><span class="o">.</span><span class="n">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__s2</span><span class="p">,</span>
                                              <span class="n">nimages</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_images</span><span class="p">,</span>
                                              <span class="n">interpolate_lattices</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="n">images</span> <span class="o">=</span> <span class="n">images_0</span> <span class="o">+</span> <span class="n">images_1</span>
            <span class="n">images</span> <span class="o">=</span> <span class="n">images</span><span class="p">[::</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">images</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span><span class="o">.</span><span class="n">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__s2</span><span class="p">,</span>
                                           <span class="n">nimages</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_images</span><span class="p">,</span>
                                           <span class="n">interpolate_lattices</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">site_i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__relax_sites</span><span class="p">:</span>
            <span class="n">start_f</span> <span class="o">=</span> <span class="n">images</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site_i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span>
            <span class="n">end_f</span> <span class="o">=</span> <span class="n">images</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site_i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span>

            <span class="n">path</span> <span class="o">=</span> <span class="n">NEBPathfinder</span><span class="o">.</span><span class="n">string_relax</span><span class="p">(</span>
                <span class="n">NEBPathfinder</span><span class="o">.</span><span class="n">__f2d</span><span class="p">(</span><span class="n">start_f</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">),</span>
                <span class="n">NEBPathfinder</span><span class="o">.</span><span class="n">__f2d</span><span class="p">(</span><span class="n">end_f</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">),</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">,</span>
                <span class="n">n_images</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_images</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span>
                <span class="n">dr</span><span class="o">=</span><span class="p">[</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">a</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">b</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__s1</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">c</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                <span class="p">])</span>
            <span class="k">for</span> <span class="n">image_i</span><span class="p">,</span> <span class="n">image</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">images</span><span class="p">):</span>
                <span class="n">image</span><span class="o">.</span><span class="n">translate_sites</span><span class="p">(</span>
                    <span class="n">site_i</span><span class="p">,</span>
                    <span class="n">NEBPathfinder</span><span class="o">.</span><span class="n">__d2f</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="n">image_i</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">)</span> <span class="o">-</span>
                    <span class="n">image</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site_i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">,</span>
                    <span class="n">frac_coords</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__images</span> <span class="o">=</span> <span class="n">images</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">images</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a list of structures interpolating between the start and</span>
<span class="sd">        endpoint structures.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__images</span>

<div class="viewcode-block" id="NEBPathfinder.plot_images"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.NEBPathfinder.plot_images">[docs]</a>    <span class="k">def</span> <span class="nf">plot_images</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates a POSCAR with the calculated diffusion path with respect to the first endpoint.</span>
<span class="sd">        :param outfile: Output file for the POSCAR</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sum_struct</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__images</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">sites</span>
        <span class="k">for</span> <span class="n">image</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__images</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">site_i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__relax_sites</span><span class="p">:</span>
                <span class="n">sum_struct</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="n">PeriodicSite</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site_i</span><span class="p">]</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span>
                                 <span class="n">image</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="n">site_i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">,</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">__images</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                 <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                 <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
        <span class="n">sum_struct</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_sites</span><span class="p">(</span><span class="n">sum_struct</span><span class="p">,</span> <span class="n">validate_proximity</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="p">(</span><span class="n">sum_struct</span><span class="p">)</span>
        <span class="n">p</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="n">outfile</span><span class="p">)</span></div>

<div class="viewcode-block" id="NEBPathfinder.string_relax"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.NEBPathfinder.string_relax">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">string_relax</span><span class="p">(</span><span class="n">start</span><span class="p">,</span>
                     <span class="n">end</span><span class="p">,</span>
                     <span class="n">V</span><span class="p">,</span>
                     <span class="n">n_images</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span>
                     <span class="n">dr</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                     <span class="n">h</span><span class="o">=</span><span class="mf">3.0</span><span class="p">,</span>
                     <span class="n">k</span><span class="o">=</span><span class="mf">0.17</span><span class="p">,</span>
                     <span class="n">min_iter</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                     <span class="n">max_iter</span><span class="o">=</span><span class="mi">10000</span><span class="p">,</span>
                     <span class="n">max_tol</span><span class="o">=</span><span class="mf">5e-6</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Implements path relaxation via the elastic band method. In general, the</span>
<span class="sd">        method is to define a path by a set of points (images) connected with</span>
<span class="sd">        bands with some elasticity constant k. The images then relax along the</span>
<span class="sd">        forces found in the potential field V, counterbalanced by the elastic</span>
<span class="sd">        response of the elastic band. In general the endpoints of the band can</span>
<span class="sd">        be allowed to relax also to their local minima, but in this calculation</span>
<span class="sd">        they are kept fixed.</span>

<span class="sd">        Args:</span>
<span class="sd">            start, end: Endpoints of the path calculation given in discrete</span>
<span class="sd">                coordinates with respect to the grid in V</span>
<span class="sd">            V: potential field through which to calculate the path</span>
<span class="sd">            n_images: number of images used to define the path. In general</span>
<span class="sd">                anywhere from 20 to 40 seems to be good.</span>
<span class="sd">            dr: Conversion ratio from discrete coordinates to real coordinates</span>
<span class="sd">                for each of the three coordinate vectors</span>
<span class="sd">            h: Step size for the relaxation. h = 0.1 works reliably, but is</span>
<span class="sd">                slow. h=10 diverges with large gradients but for the types of</span>
<span class="sd">                gradients seen in CHGCARs, works pretty reliably</span>
<span class="sd">            k: Elastic constant for the band (in real units, not discrete)</span>
<span class="sd">            min_iter, max_iter: Number of optimization steps the string will</span>
<span class="sd">                take before exiting (even if unconverged)</span>
<span class="sd">            max_tol: Convergence threshold such that if the string moves by</span>
<span class="sd">                less than max_tol in a step, and at least min_iter steps have</span>
<span class="sd">                passed, the algorithm will terminate. Depends strongly on the</span>
<span class="sd">                size of the gradients in V, but 5e-6 works reasonably well for</span>
<span class="sd">                CHGCARs.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1">#</span>
        <span class="c1"># This code is based on the MATLAB example provided by</span>
        <span class="c1"># Prof. Eric Vanden-Eijnden of NYU</span>
        <span class="c1"># (http://www.cims.nyu.edu/~eve2/main.htm)</span>
        <span class="c1">#</span>

        <span class="c1"># logger.debug(&quot;Getting path from {} to {} (coords wrt V grid)&quot;.format(start, end))</span>

        <span class="c1"># Set parameters</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">dr</span><span class="p">:</span>
            <span class="n">dr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
                <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">V</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">V</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">V</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dr</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="n">keff</span> <span class="o">=</span> <span class="n">k</span> <span class="o">*</span> <span class="n">dr</span> <span class="o">*</span> <span class="n">n_images</span>
        <span class="n">h0</span> <span class="o">=</span> <span class="n">h</span>

        <span class="c1"># Initialize string</span>
        <span class="n">g1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n_images</span><span class="p">)</span>
        <span class="n">s0</span> <span class="o">=</span> <span class="n">start</span>
        <span class="n">s1</span> <span class="o">=</span> <span class="n">end</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">g</span> <span class="o">*</span> <span class="p">(</span><span class="n">s1</span> <span class="o">-</span> <span class="n">s0</span><span class="p">)</span> <span class="k">for</span> <span class="n">g</span> <span class="ow">in</span> <span class="n">g1</span><span class="p">])</span> <span class="o">+</span> <span class="n">s0</span>
        <span class="n">ds</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">ls</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cumsum</span><span class="p">(</span><span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">ls</span> <span class="o">=</span> <span class="n">ls</span> <span class="o">/</span> <span class="n">ls</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">fi</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">ls</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">fi</span><span class="p">(</span><span class="n">g1</span><span class="p">)</span>

        <span class="c1"># Evaluate initial distances (for elastic equilibrium)</span>
        <span class="n">ds0_plus</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">ds0_minus</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">ds0_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds0_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds0_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">ds0_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds0_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds0_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

        <span class="c1"># Evaluate potential gradient outside the loop, as potential does not</span>
        <span class="c1"># change per step in this approximation.</span>
        <span class="n">dV</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">gradient</span><span class="p">(</span><span class="n">V</span><span class="p">)</span>

        <span class="c1"># Evolve string</span>
        <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">max_iter</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">step</span> <span class="o">&gt;</span> <span class="n">min_iter</span><span class="p">:</span>
                <span class="c1"># Gradually decay step size to prevent oscillations</span>
                <span class="n">h</span> <span class="o">=</span> <span class="n">h0</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">2.0</span> <span class="o">*</span> <span class="p">(</span><span class="n">step</span> <span class="o">-</span> <span class="n">min_iter</span><span class="p">)</span> <span class="o">/</span> <span class="n">max_iter</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">h</span> <span class="o">=</span> <span class="n">h0</span>
            <span class="c1"># Calculate forces acting on string</span>
            <span class="n">d</span> <span class="o">=</span> <span class="n">V</span><span class="o">.</span><span class="n">shape</span>
            <span class="n">s0</span> <span class="o">=</span> <span class="n">s</span>
            <span class="n">edV</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span>
                <span class="n">dV</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
                <span class="o">/</span> <span class="n">dr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">dV</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
                <span class="o">/</span> <span class="n">dr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">dV</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="nb">int</span><span class="p">(</span><span class="n">pt</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
                <span class="o">/</span> <span class="n">dr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="p">]</span> <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">s</span><span class="p">])</span>
            <span class="c1"># if(step % 100 == 0):</span>
            <span class="c1">#    logger.debug(edV)</span>

            <span class="c1"># Update according to force due to potential and string elasticity</span>
            <span class="n">ds_plus</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">ds_minus</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">ds_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds_plus</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">ds_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds_minus</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">Fpot</span> <span class="o">=</span> <span class="n">edV</span>
            <span class="n">Fel</span> <span class="o">=</span> <span class="n">keff</span> <span class="o">*</span> <span class="p">(</span><span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds_plus</span><span class="p">)</span> <span class="o">-</span>
                          <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds0_plus</span><span class="p">))</span> <span class="o">*</span> <span class="p">(</span><span class="n">ds_plus</span> <span class="o">/</span> <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds_plus</span><span class="p">))</span>
            <span class="n">Fel</span> <span class="o">+=</span> <span class="n">keff</span> <span class="o">*</span> <span class="p">(</span><span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds_minus</span><span class="p">)</span> <span class="o">-</span>
                           <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds0_minus</span><span class="p">))</span> <span class="o">*</span> <span class="p">(</span><span class="n">ds_minus</span> <span class="o">/</span> <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds_minus</span><span class="p">))</span>
            <span class="n">s</span> <span class="o">-=</span> <span class="n">h</span> <span class="o">*</span> <span class="p">(</span><span class="n">Fpot</span> <span class="o">+</span> <span class="n">Fel</span><span class="p">)</span>

            <span class="c1"># Fix endpoints</span>
            <span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">s0</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">s</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">s0</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

            <span class="c1"># Reparametrize string</span>
            <span class="n">ds</span> <span class="o">=</span> <span class="n">s</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">ls</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cumsum</span><span class="p">(</span><span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
            <span class="n">ls</span> <span class="o">=</span> <span class="n">ls</span> <span class="o">/</span> <span class="n">ls</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">fi</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">ls</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">fi</span><span class="p">(</span><span class="n">g1</span><span class="p">)</span>

            <span class="n">tol</span> <span class="o">=</span> <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">((</span><span class="n">s</span> <span class="o">-</span> <span class="n">s0</span><span class="p">)</span> <span class="o">*</span> <span class="n">dr</span><span class="p">)</span> <span class="o">/</span> <span class="n">n_images</span> <span class="o">/</span> <span class="n">h</span>

            <span class="k">if</span> <span class="n">tol</span> <span class="o">&gt;</span> <span class="mf">1e10</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;Pathfinding failed, path diverged! Consider reducing h to &quot;</span>
                    <span class="s2">&quot;avoid divergence.&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">step</span> <span class="o">&gt;</span> <span class="n">min_iter</span> <span class="ow">and</span> <span class="n">tol</span> <span class="o">&lt;</span> <span class="n">max_tol</span><span class="p">:</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Converged at step </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">))</span>
                <span class="k">break</span>

            <span class="k">if</span> <span class="n">step</span> <span class="o">%</span> <span class="mi">100</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Step </span><span class="si">{}</span><span class="s2"> - ds = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">,</span> <span class="n">tol</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">s</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">__f2d</span><span class="p">(</span><span class="n">frac_coords</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Converts fractional coordinates to discrete coordinates with respect to</span>
<span class="sd">        the grid size of v</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># frac_coords = frac_coords % 1</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span>
            <span class="nb">int</span><span class="p">(</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
            <span class="nb">int</span><span class="p">(</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
            <span class="nb">int</span><span class="p">(</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="p">])</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">__d2f</span><span class="p">(</span><span class="n">disc_coords</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Converts a point given in discrete coordinates withe respect to the</span>
<span class="sd">        grid in v to fractional coordinates.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span>
            <span class="n">disc_coords</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">disc_coords</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
            <span class="n">disc_coords</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="p">])</span></div>


<div class="viewcode-block" id="StaticPotential"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.StaticPotential">[docs]</a><span class="k">class</span> <span class="nc">StaticPotential</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Defines a general static potential for diffusion calculations. Implements</span>
<span class="sd">    grid-rescaling and smearing for the potential grid. Also provides a</span>
<span class="sd">    function to normalize the potential from 0 to 1 (recommended).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">struct</span><span class="p">,</span> <span class="n">pot</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param struct: atomic structure of the potential</span>
<span class="sd">        :param pot: volumentric data to be used as a potential</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="n">pot</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__s</span> <span class="o">=</span> <span class="n">struct</span>

<div class="viewcode-block" id="StaticPotential.get_v"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.StaticPotential.get_v">[docs]</a>    <span class="k">def</span> <span class="nf">get_v</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the potential</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span></div>

<div class="viewcode-block" id="StaticPotential.normalize"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.StaticPotential.normalize">[docs]</a>    <span class="k">def</span> <span class="nf">normalize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets the potential range 0 to 1.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">amin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">amax</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">)</span></div>

<div class="viewcode-block" id="StaticPotential.rescale_field"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.StaticPotential.rescale_field">[docs]</a>    <span class="k">def</span> <span class="nf">rescale_field</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_dim</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Changes the discretization of the potential field by linear</span>
<span class="sd">        interpolation. This is necessary if the potential field</span>
<span class="sd">        obtained from DFT is strangely skewed, or is too fine or coarse. Obeys</span>
<span class="sd">        periodic boundary conditions at the edges of</span>
<span class="sd">        the cell. Alternatively useful for mixing potentials that originally</span>
<span class="sd">        are on different grids.</span>

<span class="sd">        :param new_dim: tuple giving the numpy shape of the new grid</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">v_dim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="o">.</span><span class="n">shape</span>
        <span class="n">padded_v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">,</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;wrap&#39;</span><span class="p">)</span>
        <span class="n">ogrid_list</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span>
            <span class="nb">list</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndindex</span><span class="p">(</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
        <span class="p">])</span>
        <span class="n">v_ogrid</span> <span class="o">=</span> <span class="n">padded_v</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span>
            <span class="p">((</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">ngrid_a</span><span class="p">,</span> <span class="n">ngrid_b</span><span class="p">,</span> <span class="n">ngrid_c</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mgrid</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span>
                                              <span class="n">new_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span>
                                              <span class="n">new_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">0</span><span class="p">:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]:</span><span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/</span>
                                              <span class="n">new_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>

        <span class="n">v_ngrid</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">interpolate</span><span class="o">.</span><span class="n">griddata</span><span class="p">(</span><span class="n">ogrid_list</span><span class="p">,</span>
                                             <span class="n">v_ogrid</span><span class="p">,</span>
                                             <span class="p">(</span><span class="n">ngrid_a</span><span class="p">,</span> <span class="n">ngrid_b</span><span class="p">,</span> <span class="n">ngrid_c</span><span class="p">),</span>
                                             <span class="n">method</span><span class="o">=</span><span class="s1">&#39;linear&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span>
                                                 <span class="p">(</span><span class="n">new_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">new_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                                  <span class="n">new_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="n">v_ngrid</span></div>

<div class="viewcode-block" id="StaticPotential.gaussian_smear"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.StaticPotential.gaussian_smear">[docs]</a>    <span class="k">def</span> <span class="nf">gaussian_smear</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Applies an isotropic Gaussian smear of width (standard deviation) r to</span>
<span class="sd">        the potential field. This is necessary to avoid finding paths through</span>
<span class="sd">        narrow minima or nodes that may exist in the field (although any</span>
<span class="sd">        potential or charge distribution generated from GGA should be</span>
<span class="sd">        relatively smooth anyway). The smearing obeys periodic</span>
<span class="sd">        boundary conditions at the edges of the cell.</span>

<span class="sd">        :param r - Smearing width in cartesian coordinates, in the same units</span>
<span class="sd">            as the structure lattice vectors</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Since scaling factor in fractional coords is not isotropic, have to</span>
        <span class="c1"># have different radii in 3 directions</span>
        <span class="n">a_lat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">a</span>
        <span class="n">b_lat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">b</span>
        <span class="n">c_lat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">c</span>

        <span class="c1"># Conversion factors for discretization of v</span>
        <span class="n">v_dim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="o">.</span><span class="n">shape</span>
        <span class="n">r_frac</span> <span class="o">=</span> <span class="p">(</span><span class="n">r</span> <span class="o">/</span> <span class="n">a_lat</span><span class="p">,</span> <span class="n">r</span> <span class="o">/</span> <span class="n">b_lat</span><span class="p">,</span> <span class="n">r</span> <span class="o">/</span> <span class="n">c_lat</span><span class="p">)</span>
        <span class="n">r_disc</span> <span class="o">=</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">r_frac</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">])),</span>
                  <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">r_frac</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span>
                  <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">r_frac</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span>

        <span class="c1"># Apply smearing</span>
        <span class="c1"># Gaussian filter</span>
        <span class="n">gauss_dist</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span>
            <span class="p">(</span><span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">g_a</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">g_b</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">g_c</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
                                     <span class="mf">1.0</span><span class="p">):</span>
                    <span class="n">g</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
                        <span class="p">[</span><span class="n">g_a</span> <span class="o">/</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">g_b</span> <span class="o">/</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">g_c</span> <span class="o">/</span> <span class="n">v_dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span><span class="o">.</span><span class="n">T</span>
                    <span class="n">gauss_dist</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">g_a</span> <span class="o">+</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">])][</span><span class="nb">int</span><span class="p">(</span><span class="n">g_b</span> <span class="o">+</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">])][</span><span class="nb">int</span><span class="p">(</span>
                        <span class="n">g_c</span> <span class="o">+</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span> <span class="o">=</span> <span class="n">la</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">,</span> <span class="n">g</span><span class="p">))</span> <span class="o">/</span> <span class="n">r</span>
        <span class="n">gauss</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">stats</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="n">gauss_dist</span><span class="p">)</span>
        <span class="n">gauss</span> <span class="o">=</span> <span class="n">gauss</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">gauss</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="n">padded_v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__v</span><span class="p">,</span>
                          <span class="p">((</span><span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="p">(</span><span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                           <span class="p">(</span><span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">r_disc</span><span class="p">[</span><span class="mi">2</span><span class="p">])),</span>
                          <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;wrap&#39;</span><span class="p">)</span>
        <span class="n">smeared_v</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">signal</span><span class="o">.</span><span class="n">convolve</span><span class="p">(</span><span class="n">padded_v</span><span class="p">,</span> <span class="n">gauss</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;valid&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__v</span> <span class="o">=</span> <span class="n">smeared_v</span></div></div>


<div class="viewcode-block" id="ChgcarPotential"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.ChgcarPotential">[docs]</a><span class="k">class</span> <span class="nc">ChgcarPotential</span><span class="p">(</span><span class="n">StaticPotential</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Implements a potential field based on the charge density output from VASP.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chgcar</span><span class="p">,</span> <span class="n">smear</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param chgcar: Chgcar object based on a VASP run of the structure of</span>
<span class="sd">            interest (Chgcar.from_file(&quot;CHGCAR&quot;))</span>
<span class="sd">        :param smear: Whether or not to apply a Gaussian smearing to the</span>
<span class="sd">            potential</span>
<span class="sd">        :param normalize: Whether or not to normalize the potential to range</span>
<span class="sd">            from 0 to 1</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">chgcar</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">v</span> <span class="o">/</span> <span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">v</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="n">StaticPotential</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chgcar</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">smear</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">gaussian_smear</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">normalize</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span></div>


<div class="viewcode-block" id="FreeVolumePotential"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.FreeVolumePotential">[docs]</a><span class="k">class</span> <span class="nc">FreeVolumePotential</span><span class="p">(</span><span class="n">StaticPotential</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Implements a potential field based on geometric distances from atoms in the</span>
<span class="sd">    structure - basically, the potential</span>
<span class="sd">    is lower at points farther away from any atoms in the structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">struct</span><span class="p">,</span> <span class="n">dim</span><span class="p">,</span> <span class="n">smear</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param struct: Unit cell on which to base the potential</span>
<span class="sd">        :param dim: Grid size for the potential</span>
<span class="sd">        :param smear: Whether or not to apply a Gaussian smearing to the</span>
<span class="sd">            potential</span>
<span class="sd">        :param normalize: Whether or not to normalize the potential to range</span>
<span class="sd">            from 0 to 1</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__s</span> <span class="o">=</span> <span class="n">struct</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">FreeVolumePotential</span><span class="o">.</span><span class="n">__add_gaussians</span><span class="p">(</span><span class="n">struct</span><span class="p">,</span> <span class="n">dim</span><span class="p">)</span>
        <span class="n">StaticPotential</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">struct</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">smear</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">gaussian_smear</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">normalize</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">__add_gaussians</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">dim</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="mf">1.5</span><span class="p">):</span>
        <span class="n">gauss_dist</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">dim</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">a_d</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">1.0</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">b_d</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mf">1.0</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">c_d</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mf">1.0</span><span class="p">):</span>
                    <span class="n">coords_f</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
                        <span class="p">[</span><span class="n">a_d</span> <span class="o">/</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">b_d</span> <span class="o">/</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">c_d</span> <span class="o">/</span> <span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
                    <span class="n">d_f</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="n">coords_f</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">a</span><span class="p">),</span>
                                 <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
                    <span class="c1"># logger.debug(d_f)</span>
                    <span class="n">gauss_dist</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">a_d</span><span class="p">)][</span><span class="nb">int</span><span class="p">(</span><span class="n">b_d</span><span class="p">)][</span><span class="nb">int</span><span class="p">(</span><span class="n">c_d</span><span class="p">)]</span> <span class="o">=</span> <span class="n">d_f</span> <span class="o">/</span> <span class="n">r</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">stats</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="n">gauss_dist</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">v</span></div>


<div class="viewcode-block" id="MixedPotential"><a class="viewcode-back" href="../../../pymatgen.analysis.path_finder.html#pymatgen.analysis.path_finder.MixedPotential">[docs]</a><span class="k">class</span> <span class="nc">MixedPotential</span><span class="p">(</span><span class="n">StaticPotential</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Implements a potential that is a weighted sum of some other potentials</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">potentials</span><span class="p">,</span> <span class="n">coefficients</span><span class="p">,</span> <span class="n">smear</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            potentials: List of objects extending the StaticPotential superclass</span>
<span class="sd">            coefficients: Mixing weights for the elements of the potentials list</span>
<span class="sd">            smear: Whether or not to apply a Gaussian smearing to the potential</span>
<span class="sd">            normalize: Whether or not to normalize the potential to range from</span>
<span class="sd">                0 to 1</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">potentials</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_v</span><span class="p">()</span> <span class="o">*</span> <span class="n">coefficients</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">potentials</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">__s</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">potentials</span><span class="p">)):</span>
            <span class="n">v</span> <span class="o">+=</span> <span class="n">potentials</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">get_v</span><span class="p">()</span> <span class="o">*</span> <span class="n">coefficients</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="n">StaticPotential</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">smear</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">gaussian_smear</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">normalize</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.path_finder</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>